#include <stdio.h>
#include <mstring.h>

int main()
{
  FILE* fp = fopen("mime.txt", "r");
  MString ans = newString();
  addRawString(&ans, "#include <mime.h>\n#include <stdio.h>\n#include <string.h>\n\nconst char* getMimeType(const char* filename)\n{\n  const char* extension = strrchr(filename, '.');\n  if (extension != NULL)\n  {\n    if (strcmp(extension, \".");
  int status = 0;
  char ch;
  while ((ch = fgetc(fp)) != EOF)
  {
    switch (status)
    {
      case 0:
        if (ch == ' ' || ch == '\t')
        {
          status = 1;
          addRawString(&ans, "\") == 0)\n    {\n      return \"");
        }
        else
        {
          addChar(&ans, ch);
        }
        break;
      case 1:
        if (ch == '\n')
        {
          status = 0;
          addRawString(&ans, "\";\n    }\n    else if (strcmp(extension, \".");
        }
        else if (ch != ' ' && ch != '\t')
        {
          addChar(&ans, ch);
        }
        break;
    }
  }
  addRawString(&ans, "\n  }\n  return \"application/octet-stream\";\n}");
  fclose(fp);
  fp = fopen("mime.c", "w");
  fwrite(ans.data, ans.ptr, 1, fp);
  fclose(fp);
  freeString(ans);
}
